package com.farm.monitors.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.farm.common.annotation.Log;
import com.farm.common.core.controller.BaseController;
import com.farm.common.core.domain.AjaxResult;
import com.farm.common.enums.BusinessType;
import com.farm.monitors.domain.Monitors;
import com.farm.monitors.service.IMonitorsService;
import com.farm.common.utils.poi.ExcelUtil;
import com.farm.common.core.page.TableDataInfo;

/**
 * 监测管理Controller
 * 
 * @author yd
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/monitors/monitors")
public class MonitorsController extends BaseController
{
    @Autowired
    private IMonitorsService monitorsService;

    /**
     * 查询监测管理列表
     */
    @PreAuthorize("@ss.hasPermi('monitors:monitors:list')")
    @GetMapping("/list")
    public TableDataInfo list(Monitors monitors)
    {
        startPage();
        List<Monitors> list = monitorsService.selectMonitorsList(monitors);
        return getDataTable(list);
    }

    /**
     * 导出监测管理列表
     */
    @PreAuthorize("@ss.hasPermi('monitors:monitors:export')")
    @Log(title = "监测管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Monitors monitors)
    {
        List<Monitors> list = monitorsService.selectMonitorsList(monitors);
        ExcelUtil<Monitors> util = new ExcelUtil<Monitors>(Monitors.class);
        util.exportExcel(response, list, "监测管理数据");
    }

    /**
     * 获取监测管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('monitors:monitors:query')")
    @GetMapping(value = "/{monitorsId}")
    public AjaxResult getInfo(@PathVariable("monitorsId") Long monitorsId)
    {
        return success(monitorsService.selectMonitorsByMonitorsId(monitorsId));
    }

    /**
     * 新增监测管理
     */
    @PreAuthorize("@ss.hasPermi('monitors:monitors:add')")
    @Log(title = "监测管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Monitors monitors)
    {
        return toAjax(monitorsService.insertMonitors(monitors));
    }

    /**
     * 修改监测管理
     */
    @PreAuthorize("@ss.hasPermi('monitors:monitors:edit')")
    @Log(title = "监测管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Monitors monitors)
    {
        return toAjax(monitorsService.updateMonitors(monitors));
    }

    /**
     * 删除监测管理
     */
    @PreAuthorize("@ss.hasPermi('monitors:monitors:remove')")
    @Log(title = "监测管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{monitorsIds}")
    public AjaxResult remove(@PathVariable Long[] monitorsIds)
    {
        return toAjax(monitorsService.deleteMonitorsByMonitorsIds(monitorsIds));
    }
}
